package com.xrf;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class ContractManagement {
    private String marketLetter;
    private Double deliveryInformation;
    private String financialInformation;
    private Long contractInformation;
    private Double milestoneInformation;
    private String listOfContracts;
    private Long contractNo;
    private String nameOfTheContract;
    private Long andHisType;
    private Double operate;

    private static List<ContractManagement> list = new ArrayList<>();
    private static Scanner scanner = new Scanner(System.in);

    public ContractManagement() {}

    public ContractManagement(String marketLetter, Double deliveryInformation, String financialInformation,
                            Long contractInformation, Double milestoneInformation, String listOfContracts,
                            Long contractNo, String nameOfTheContract, Long andHisType, Double operate) {
        this.marketLetter = marketLetter;
        this.deliveryInformation = deliveryInformation;
        this.financialInformation = financialInformation;
        this.contractInformation = contractInformation;
        this.milestoneInformation = milestoneInformation;
        this.listOfContracts = listOfContracts;
        this.contractNo = contractNo;
        this.nameOfTheContract = nameOfTheContract;
        this.andHisType = andHisType;
        this.operate = operate;
    }

    // Getter and Setter methods
    public String getMarketLetter() { return marketLetter; }
    public void setMarketLetter(String marketLetter) { this.marketLetter = marketLetter; }
    public Double getDeliveryInformation() { return deliveryInformation; }
    public void setDeliveryInformation(Double deliveryInformation) { this.deliveryInformation = deliveryInformation; }
    public String getFinancialInformation() { return financialInformation; }
    public void setFinancialInformation(String financialInformation) { this.financialInformation = financialInformation; }
    public Long getContractInformation() { return contractInformation; }
    public void setContractInformation(Long contractInformation) { this.contractInformation = contractInformation; }
    public Double getMilestoneInformation() { return milestoneInformation; }
    public void setMilestoneInformation(Double milestoneInformation) { this.milestoneInformation = milestoneInformation; }
    public String getListOfContracts() { return listOfContracts; }
    public void setListOfContracts(String listOfContracts) { this.listOfContracts = listOfContracts; }
    public Long getContractNo() { return contractNo; }
    public void setContractNo(Long contractNo) { this.contractNo = contractNo; }
    public String getNameOfTheContract() { return nameOfTheContract; }
    public void setNameOfTheContract(String nameOfTheContract) { this.nameOfTheContract = nameOfTheContract; }
    public Long getAndHisType() { return andHisType; }
    public void setAndHisType(Long andHisType) { this.andHisType = andHisType; }
    public Double getOperate() { return operate; }
    public void setOperate(Double operate) { this.operate = operate; }

    @Override
    public String toString() {
        StringBuilder builder = new StringBuilder();
        builder.append("市场信息:").append(marketLetter).append("\t");
        builder.append("交付信息:").append(deliveryInformation).append("\t");
        builder.append("财务信息:").append(financialInformation).append("\t");
        builder.append("合同信息:").append(contractInformation).append("\t");
        builder.append("里程碑信息:").append(milestoneInformation).append("\t");
        builder.append("合同列表:").append(listOfContracts).append("\t");
        builder.append("合同编号:").append(contractNo).append("\t");
        builder.append("合同名称:").append(nameOfTheContract).append("\t");
        builder.append("和他类型:").append(andHisType).append("\t");
        builder.append("操作:").append(operate).append("\t");
        return builder.toString();
    }

    public static void addData() {
        System.out.println("--------添加数据-------");
        System.out.println("请输入市场信息：");
        String marketLetter = scanner.next();
        System.out.println("请输入交付信息：");
        Double deliveryInformation = scanner.nextDouble();
        System.out.println("请输入财务信息：");
        String financialInformation = scanner.next();
        System.out.println("请输入合同信息：");
        Long contractInformation = scanner.nextLong();
        System.out.println("请输入里程碑信息：");
        Double milestoneInformation = scanner.nextDouble();
        System.out.println("请输入合同列表：");
        String listOfContracts = scanner.next();
        System.out.println("请输入合同编号：");
        Long contractNo = scanner.nextLong();
        System.out.println("请输入合同名称：");
        String nameOfTheContract = scanner.next();
        System.out.println("请输入和他类型：");
        Long andHisType = scanner.nextLong();
        System.out.println("请输入操作：");
        Double operate = scanner.nextDouble();
        
        ContractManagement data = new ContractManagement(marketLetter, deliveryInformation, financialInformation,
                                                       contractInformation, milestoneInformation, listOfContracts,
                                                       contractNo, nameOfTheContract, andHisType, operate);
        list.add(data);
    }

    public static void removeData() {
        System.out.println("--------删除数据-------");
        System.out.println("请输入索引：");
        int index = scanner.nextInt();
        if (index >= 0 && index < list.size()) {
            list.remove(index);
            System.out.println("删除成功！");
        } else {
            System.out.println("索引无效！");
        }
    }

    public static void updateData() {
        System.out.println("--------修改数据-------");
        System.out.println("请输入索引：");
        int index = scanner.nextInt();
        if (index >= 0 && index < list.size()) {
            System.out.println("请输入市场信息：");
            String marketLetter = scanner.next();
            System.out.println("请输入交付信息：");
            Double deliveryInformation = scanner.nextDouble();
            System.out.println("请输入财务信息：");
            String financialInformation = scanner.next();
            System.out.println("请输入合同信息：");
            Long contractInformation = scanner.nextLong();
            System.out.println("请输入里程碑信息：");
            Double milestoneInformation = scanner.nextDouble();
            System.out.println("请输入合同列表：");
            String listOfContracts = scanner.next();
            System.out.println("请输入合同编号：");
            Long contractNo = scanner.nextLong();
            System.out.println("请输入合同名称：");
            String nameOfTheContract = scanner.next();
            System.out.println("请输入和他类型：");
            Long andHisType = scanner.nextLong();
            System.out.println("请输入操作：");
            Double operate = scanner.nextDouble();
            
            ContractManagement data = new ContractManagement(marketLetter, deliveryInformation, financialInformation,
                                                           contractInformation, milestoneInformation, listOfContracts,
                                                           contractNo, nameOfTheContract, andHisType, operate);
            list.set(index, data);
            System.out.println("修改成功！");
        } else {
            System.out.println("索引无效！");
        }
    }

    public static void displayData() {
        System.out.println("--------数据显示-------");
        for (int i = 0; i < list.size(); i++) {
            System.out.println("索引 " + i + ": " + list.get(i));
        }
    }
}